Fix Android dirs raising opaque TypeError when the app storage folder is undetectable - #547
Open
Str0k wants to merge 2 commits into
Open
Fix Android dirs raising opaque TypeError when the app storage folder is undetectable#547Str0k wants to merge 2 commits into
Str0k wants to merge 2 commits into
Conversation
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android, when the private app storage folder cannot be detected (no python4android, no pyjnius, and no recognizable /data/.../files entry on sys.path), every Android directory property (user_data_dir, user_config_dir, user_cache_dir, user_bin_dir, etc.) crashed with TypeError: expected str, bytes or os.PathLike object, not NoneType. The _android_folder() helper is documented to return str | None when detection fails, but each consumer blindly cast the result to str and passed it to path joining. After this fix, these properties raise a descriptive RuntimeError explaining that the base Android app folder cannot be determined, matching the repo's existing error style in unix.py.
The documented contract of _android_folder() allows None, so callers deserve an actionable error (or a catchable RuntimeError to fall back to another implementation) rather than an opaque TypeError from deep inside os.path.join. A new helper _require_android_folder() centralizes the None check with a clear message, and the four affected properties now use it. Implementation reason: minimal, no API signature change; the RuntimeError-with-msg pattern follows the existing unix.py precedent.
Validation:
AI assistance: implementation and independent review used Hermes with GLM 5.3. Test evidence was reproduced in clean checkouts. This does not represent a human review.
An additional model reviewed the supplied patch and evidence without executing tools.